package com.javasm.mb_store_api_final.sys_control.usercontrol.sys_menu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javasm.mb_store_api_final.sys_control.usercontrol.authority.dao.AuthorityDao;
import com.javasm.mb_store_api_final.sys_control.usercontrol.authority.entity.Authority;
import com.javasm.mb_store_api_final.sys_control.usercontrol.sys_menu.entity.SysMenu;
import com.javasm.mb_store_api_final.sys_control.usercontrol.sys_menu.dao.SysMenuDao;
import com.javasm.mb_store_api_final.sys_control.usercontrol.sys_menu.service.SysMenuService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * (SysMenu)表服务实现类
 *
 * @author makejava
 * @since 2024-07-29 20:18:20
 */
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuDao,SysMenu> implements SysMenuService {
    @Resource
    private SysMenuDao sysMenuDao;


    @Override
    public List<SysMenu> listMenu() {
        List<SysMenu> listLevel1=sysMenuDao.listMenuLevel1();
        List<SysMenu> listLevel2=sysMenuDao.listMenuLevel2();
        listLevel1.forEach(menu->{
            List<SysMenu> list=listLevel2.stream().filter(m->m.getPid().equals(menu.getId())).collect(Collectors.toList());
            menu.setChildMenus(list);
        });
        return listLevel1;
    }

    @Override
    public List<SysMenu> listMenuByRid(Integer rid) {
        List<SysMenu> menus = sysMenuDao.listMenuByRid(rid);

        List<SysMenu> firstMenus = menus.stream().filter(SysMenu::checkFirstMenu).collect(Collectors.toList());
        firstMenus.forEach(menu->{
            List<SysMenu> list=menus.stream().filter(m->m.getPid().equals(menu.getId())).collect(Collectors.toList());
            menu.setChildMenus(list);
        });
        return firstMenus;
    }


}
